﻿using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System.Data;

public class AddCoachInfo : MonoBehaviour {

    public Text tipInfo;
    public InputField inputBeta;
    public InputField inputProId0;
    public InputField inputStartnum;
    public InputField inputEndnum;
    public InputField inputProId;
    public InputField inputNumber;
    public InputField inputCheckId;
    public GameObject showInfiPlane;
    int startnum;
    int endnum;
    string proid0;
    int proid1;
    int i;
    int length;
    string beta;
    string proid;
    string checkid;
    DataSet ds;
    public string s1;
    public string s2;
    public string s3;
    public string s4;
    public string s5;
    public string s6;
    public string s7;
    public string s8,s9;
    string number;

    void ShowInfo(string ss )
    {
        tipInfo.text = ss;
    }

    void Start()
    {
        length = ds.Tables[0].Rows.Count;
        if (length > 0)
        {
            inputProId.text = ds.Tables[0].Rows[length - 1][0].ToString();
        }
    }

    public void Save()
    {
        if (inputBeta.text.Length < 4)
        {
            ShowInfo("版本号输入不正确，请重新输入");
            return;
        }
        if (inputProId0.text.Length != 14)
        {
            ShowInfo("序列号前14位输入不正确，请重新输入！");
            return;
        }
        startnum = int.Parse(inputStartnum.text);
        if (startnum > 99 || startnum < 0)
        {
            ShowInfo("开始编号输入不正确，请重新输入");
            return;
        }
        endnum = int.Parse(inputEndnum.text);
        if (endnum > 99 || endnum < 0)
        {
            ShowInfo("结束编号输入不正确，请重新输入");
            return;
        }
        beta = inputBeta.text;
        proid0 = inputProId0.text;
        for (i = startnum; i <= endnum; i++)
        {
            if (i >= 0 && i < 10)
                proid = proid0 + "0" + i.ToString();
            else if (i >= 10 && i < 100)
                proid = proid0 + i.ToString();
            AddInfo();
        }
    }
    void AddInfo()
    {
        if (proid.Length == 16)
        {
            number = GetRandom._instance.GetNumber6();
            checkid = GetRandom._instance.GetCheckid8();
            Data1();
        }
        else
        {
            ShowInfo(s7);
        }
    }

    void Data1()
    {
        
        if (ds.Tables[0].Rows.Count > 0)
        {
            ShowInfo(s6);
            showInfiPlane.SetActive(false);
        }
        else
        {
            Data3();
        }
    }

    void Data3()
    {
        
        showInfiPlane.SetActive(true);
        inputProId.text = proid;
        inputNumber.text = number;
        inputCheckId.text = checkid;
        ShowInfo(s5);
    }
}
